﻿using System;
using System.Windows;

namespace ShinyWizard
{
    public class WizardRoute : FrameworkElement
    {
        #region Static

        public static DependencyProperty IsAvaliableProperty = DependencyProperty.Register(
            "IsAvaliable",
            typeof (bool),
            typeof (WizardRoute),
            new PropertyMetadata(true, IsAvaliablePropertyChanged));

        #endregion

        #region Events

        public event Action AvailabilityChanged;

        #endregion

        #region Properties

        public string StepName { get; set; }

        public string TargetStepName { get; set; }

        public bool IsAvaliable
        {
            get { return (bool)GetValue(IsAvaliableProperty); }
            set { SetValue(IsAvaliableProperty, value); }
        }

        #endregion

        #region Methods
        
        private static void IsAvaliablePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue != e.NewValue)
            {
                var navigationRoute = (WizardRoute) d;
                navigationRoute.RaiseAvailabilityChanged();
            }
        }

        private void RaiseAvailabilityChanged()
        {
            var temp = AvailabilityChanged;
            if (temp != null)
                temp();
        }

        #endregion
    }
}